/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef VIEW_H
#define VIEW_H

#include <QFrame>
#include <QGraphicsView>
#include "common_struct/common_struct.h"

QT_BEGIN_NAMESPACE
class QLabel;
class QSlider;
class QToolButton;
class QMenu;
QT_END_NAMESPACE

class View;

class GraphicsView : public QGraphicsView
{
    Q_OBJECT
public:
    GraphicsView(View *v) : QGraphicsView(), view(v) { }
    void mousePressEvent(QGraphicsSceneMouseEvent *event);

protected:
#ifndef QT_NO_WHEELEVENT
    void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE;
#endif

private:
    View *view;
};

class View : public QFrame
{
    Q_OBJECT
public:
    explicit View(const QString &name, QWidget *parent = 0);

    QGraphicsView *view() const;

    QAction* MonitorAreaAct;
    QAction* AlertAreaAct;

signals:
    clearMap();
    clearTargets();
    setRadarParameter();
    setTrack();

    /////zhu
    clearMap(bool);
    setMapParameter();
    emitmapchange(bool bMapChange);
    emitscalechanged(float scale);

    triggeredMonitorAreaSig();
    triggeredAlertAreaSig();
    triggeredAreaSignal(AreaType type);

public slots:
    void zoomIn(int level = 5);
    void zoomOut(int level = 5);

private slots:
    void resetView();
    void setResetButtonEnabled();
    void setupMatrix();
    void rotateLeft();
    void rotateRight();

    void toggleSetting();//setRadarParameter();
    void emittomap();//clear all items
    void toogleTrackSetting();//trace setting
    void MapSetting();

    void TriggeredMonitorArea(bool flag);
    void TriggeredAlertArea(bool flag);

    //!!!!!!!!!!!!!!!!!!!zhu20180901

    void selectArea();//选择区域

public:
    bool GetCursorHandle();
    bool bCursorHandle;          //设置光标状态，1：手。 0：十字
//    bool m_bMapChange;              //小标地图标示. 0:2D; 1:3D。

//////new
protected:
    virtual void contextMenuEvent(QContextMenuEvent* e);

private:
    GraphicsView *graphicsView;
    QLabel *TitleLabel;
    QToolButton *RadarParameterButton;
    QToolButton *identifyTrackButton;
    QToolButton *clearTargetButton;
    QSlider *zoomSlider;
    QSlider *rotateSlider;
    QToolButton *resetButton;

    //////new
//    QToolButton* MapParameterButton;//预留给重新设置地图
//    QToolButton *MapChangeButton;
//    QLabel *Scalelabel;
//    uint32_t m_u32zoom;

private:
    creatActions();
    creatMenus();

    QMenu* mainMenu;
    QMenu* AreaSelectionMenu;
    QMenu* TrackerSettingMenu;
    QAction* RadarLocationAct;

    bool MonitorAreaState;
    bool AlertAreaActState;
};

class GraphicsScene : public QGraphicsScene
{
    Q_OBJECT
public:
    GraphicsScene(QWidget* parent=0);
    ~GraphicsScene();

signals:
    MonitorAreaSelecting(QPointF pos);
    AlertAreaSelecting(QPointF pos);
    MonitorAreaFinish();
    AlertAreaFinish();

    AreaSelecting(QPointF pos, AreaType type);
    AreaFinished(AreaType type);


protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;

public slots:
    void getMonitorAreaFlag();
    void getAlertAreaFlag();
    void getAreaType(AreaType type);

private:
    bool MonitorAreaSelected;
    bool AlertAreaSelected;

};

#endif // VIEW_H
